package com.king01.controller;

import com.king01.annotation.LogAnnotation;
import com.king01.annotation.LogAnnotation02;
import com.king01.entity.Staff;
import com.king01.service.StaffExSevice;
import com.king01.vo.Result;
import com.king01.vo.StaffExVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/stafftransfer")
public class StaffExController {
    @Autowired
    private StaffExSevice staffExSevice;
    @Autowired
    private HttpSession session;
    @RequestMapping("/list")
    public Result list(Integer current, Integer pageSize, @RequestBody StaffExVo staffExVo) {
        Result result = staffExSevice.findAll(current, pageSize, staffExVo);
        return result;
    }

    @RequestMapping("/update1")
    @LogAnnotation02(business_type = "调动员工操作")
    public Result update1(@RequestBody StaffExVo staffExVo) {
        Staff staff = (Staff)session.getAttribute("staff");
        Result staffByBranch = staffExSevice.findStaffByBranch(staffExVo.getBranchid());
        List<Staff> data =(List<Staff>) staffByBranch.getData();
        if(staff.getStaffid()==data.get(0).getStaffid()){
            //如果是本店店长
            // 修改审核的时间和审核人
            Result result = staffExSevice.update1(staffExVo);
            //修改部门的数据
            Result result1 = staffExSevice.updateStaffBranchAndDept(staffExVo);
            return result1;
        }else {
            return new Result(500,"对不起，你没有权限",null);
        }
    }
    @RequestMapping("/update2")
    public Result update2(@RequestBody StaffExVo staffExVo) {
        Result result = staffExSevice.update2(staffExVo);
        return result;
    }

}
